home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Wayzata's Best of Shareware PC/Windows 1
/
Wayzata's Best of Shareware for PC-Windows - Release 1 - Wayzata Technology (1993).iso
/
mac
/
DOS
/
PROGRAMG
/
COMPILE
/
HINTKINK.DOC
< prev
next >
Wrap
Text File
|
1992-08-26
|
30KB
|
914 lines
Hints and Kinks for Compiling and Linking QuickBASIC Programs
c1991 Thomas Software
Table of Contents
Contents ......................................................... 2
Introduction ..................................................... 3
What's this BC and Link stuff? ................................... 4
BC (Basic Compiler) .............................................. 5
LINK ............................................................. 5
QuickCompile's BC Options
EXE Requiring BRUNxx.EXE ..................................... 6
/T Terse Error Display ...................................... 6
/D Produce Debug Code ....................................... 6
/A Disassembled List File ................................... 7
/ZI CodeView Object Code .................................... 7
/ZD Symbolic Debugger Code .................................. 7
/S Quoted Strings to OBJ .................................... 7
/R Row-Major Order Arrays ................................... 7
/AH $DYNAMIC Arrays > 64k ................................... 7
/C:<number> Communications Routines ........................ 8
/MBF MicroSoft Binary Format ................................ 8
/X ON ERROR/RESUME <NEXT> <0> ............................... 8
/E ON ERROR/RESUME <LineNumber> ............................. 8
/V ON [event] Normal Trap ................................... 9
/W ON [event] Fast Trap ..................................... 9
NO [event] Trapping .......................................... 9
Source List File ............................................. 9
Delete OBJ Code .............................................. 9
QuickCompile's Link Options
/E EXEPACK (optimized exe size) ............................ 10
/PAU PAUSE before exe write ................................ 10
/I Show Link INFORMATION ................................... 10
/B BATCH mode (no prompts) ................................. 10
/M Create MAPFILE .......................................... 11
/LI MapFile with LINENUMBERS ............................... 11
/NOI NOIGNORECASE (observe case) ........................... 11
/NOD NODEFAULTLIBRARY (using PDQ, etc...) .................. 11
/NOE NOEXTDICTIONARY (using nocom, etc...) ................. 12
/SE:<number> SEGMENTS ...................................... 12
/CO CODEVIEW preparation ................................... 12
/FAR FAR ................................................... 12
/PAC:<number> PACKCODE ..................................... 13
/ST:<number> STACK ......................................... 13
NOCOM.OBJ (No Communications Routines) .......................... 14
NOEM.OBJ (No Floating Point Emulation) .......................... 14
SMALLERR.OBJ (No Error Messages) ................................ 15
EXISTS.BAS Module (Check for existance of a file) ............... 15
CHK4QC .......................................................... 16
- 2 -
Introduction
This Booklet is a compilation of various tips for Compiling and Linking
QuickBASIC programs from outside the QuickBASIC Environment. This info
is being provided to Registered QuickCompile users free of charge as a
guide to help produce better and more efficient programs.
We believe this material to be timely and helpful. However, no claim
to accuracy is made. Thomas Software and the Authors may not be held
liable for any circumstances that may arise from it's use.
The information presented here is not intended to teach how to compile
and link from the command line, but how to better use QuickCompile for
for this purpose.
- 3 -
What's this BC and Link stuff ?
When you write programs in QuickBASIC, you use statements and functions
that cause specific actions to occur. The PRINT statement may cause a
line of text to be printed to the screen.
EXAMPLE:
PRINT " HELLO WORLD ! "
Causes the words HELLO WORLD ! to be printed wherever
the cursor is located at the time. (Of course you already
knew this, but we're trying to keep thing simple here.)
Your computer does not really understand the meaning of the statement
"PRINT". In fact, it doesn't understand any of the statements or
functions included in the QuickBASIC Language. Computers speak Machine
language...
How do we get the computer to understand our QB programs? Two ways.
The first, is the interpreter, a feature of the QuickBASIC environment.
We use the editor to type in our programs and then press F5 (run) to
execute them. The interpreter looks at each line of our program and
translates them into machine code that the computer can understand.
Some statements in the source code (program file) are directly
translated into machine code. Others are translated into machine code
and calls to routines in the basic language's run time library.
GW Basic is an interpreted basic. You cannot run GW Basic programs
without loading the interpreter.
Secondly, QuickBASIC is a compiled Basic. It can produce .EXE files
that may be run without the help of an interpreter.
After you have written your program and tested it in the QB environment,
you may choose the "Make exe file" command from the "Run" menu.
QuickBASIC will then produce an executable (.EXE) file that runs
outside the environment. Compile programs run faster than interpreted
ones because the machine code has already been produced and does not
need to be interpreted on the fly.
QuickBASIC produces two types of .EXE files. Those that require
a runtime library (BRUN45.EXE) and those that are stand-alone.
Programs requiring BRUN are smaller because much of the machine code
is contained in the BRUN file. However, stand-alone programs generally
run faster and use less memory because everything the program needs is
self contained.
- 4 -
BC (Basic Compiler)
BC.EXE is the QuickBASIC compiler. This is the first step in turning
your source code (.BAS files) into .EXE files. BC produces .OBJ (object)
files which are combined to produce .EXE files.
There are many options to BC that specify how to, and what kind of object
file to produce. When your compile within the QB environment, you are
not allowed to change these options. This is just one of many reasons
to leave the environment for compiling.
LINK
LINK.EXE is the QuickBASIC linker. This is the final step in turning
your source code into .EXE files. Once an object file has been created
from your source, it needs to be linked (combined) with other object
files and libraries (collections of object files) to produce the .EXE
file. Like BC, Link has many options that you can't use from inside
the QB environment.
BC and Link both have uses other than those we just mentioned, but
they are beyond the scope of this booklet.
- 5 -
QuickCompile's BC Options
EXE Requiring BRUNxx.EXE
This first option allows you to specify producing an .EXE file that
requires BRUN. This is the default when you compile within the QB
environment. However, it has been our experience that most people
prefer building stand-alone .EXE files. Therefore, QuickCompile
defaults to stand-alone and specifies the /O switch (not shown).
Normally, this option is most useful if you are distributing a
software package that contains many .EXE files, and want to
conserve disk space. Also, when chaining programs, BRUNxx.EXE
operates faster because the library need not be loaded again.
If you choose this option, you must be certain that the end user has
a copy of the correct BRUNxx.EXE file, or the program will not run.
For optimum program execution speed, you will not want to use the
EXE Requiring BRUNxx.EXE option. Stand Alone executables are always
faster, use less memory, and are easier to manage.
/T Terse Error Display
Causes BC to not display the copyright notice or warning messages (if
errors are encountered) during compiling.
(/T is a QB Environment default.)
We normally don't recommend using this switch because it's helpful
to know all you can about possible errors in your program.
/D Produce Debug Code
Produces debugging code for runtime error checking. Also Enables
CTRL-BREAK.
This option is useful when developing and debugging a program because
you may hit CTRL-BREAK at any point in program execution and exit.
QuickBASIC programs do not check for overflow errors when performing
integer math. /D enables integer math overflow error checking.
When you're not using the /AH switch, compiled QuickBASIC programs do
not check to see if an array is in bounds or not. If an attempt is
made to access an array element that is out of bounds, other data
will be overwritten without warning. Using the /D switch will warn
when such a condition exists.
However, you should not use the /D switch in the final version of
your program because it slows execution and adds to the file size.
- 6 -
/A Disassembled List File
Produces a list file showing each source line disassembled, and
it's compiler generated assembly language instructions.
/ZI CodeView Object Code
Produces an object file of information for use by the MicroSoft
CodeView debugger that comes with several of their other languages.
/ZD Symbolic Debugger Code
Produces an object file with line numbers that correspond to the
lines of your source file. Useful for source level debugging with
MicroSoft's SYMDEB Symbolic Debugger.
/S Quoted Strings to OBJ
Places quoted strings in the object file instead of the symbol
table. Useful for avoiding "Out of memory" errors in programs
with many string constants.
This option may also reduce the size of your .EXE file.
/R Row-Major Order Arrays
Useful when using routines from other languages that store arrays
in this order. QuickBasic stores it's arrays in column-major order
normally.
/AH $DYNAMIC Arrays > 64k
Allows arrays of Records, fixed-length strings, and numeric data
to be dynamic. These arrays may use all of available memory.
When not used, and arrays are not dimensioned with REDIM, arrays are
Static and are limited to a maximum of 64k each.
Note that variable-length string arrays are always Static. Only
fixed-length string arrays may be Dynamic and make use of this option.
- 7 -
/C:<number> Communications Routines
Sets the receive buffer size of the comm ports. Default is 512
bytes total for both ports. Maximum receive buffer size may be
set to 32,767 bytes. This option has no effect on the transmit
buffer which is set to 128 bytes for each port and can't be
changed.
Note that communications routines may be unnecessarily placed in
your .EXE file without your knowledge, even if you don't specify
this switch. Read the section on NOCOM.OBJ to insure that your
programs don't waste 4K of disk space with uncalled comm routines.
/MBF MicroSoft Binary Format
Allows your programs to read and write floating point values
stored in MicroSoft Binary Format. MKS$, MKD$, CVS, and CVD
functions are converted to MKSMBF$, MKDMBF$, CVSMBF, and CVDMBF.
/X ON ERROR/RESUME <NEXT> <0>
Use when your program contains ON ERROR with RESUME, RESUME NEXT,
or RESUME 0.
Note: Using ON ERROR will slow program execution and cause your
.EXE file size to noticeable increase.
Avoid using any ON ERROR statements in your program if at
all possible. Many Shareware and Commercial add-on libraries
have functions with built in error checking to help avoid
QuickBASIC's ON ERROR.
One often needed error trap is checking to see if a file
exists. We have created a Basic module to help you avoid
using ON ERROR in this case. See the section on EXISTS.BAS
for details.
/E ON ERROR/RESUME <LineNumber>
Use when your program contains an ON ERROR with a RESUME statement
containing a line number.
See Note above under /X for important information that applies to
use of ON ERROR.
- 8 -
/V ON [event] Normal Trap
Use for event trapping the Comm Port (COM), LightPen (PEN),
JoyStick (STRIG), Timer (TIMER), Music Buffer (PLAY) and
Function Keys (KEY).
Checks between each program statement for an event to occur. This
will cause events to be recognized earlier, but will slow program
execution and increase file size because BC must place code to
check for events between each program statement.
/W ON [event] Fast Trap
Same as /V option, but checks at each program label (or line number)
for an event to occur.
Checks for events only at labels (or line numbers). Because event
checking code is only placed at labels, you control where and how
much event checking is performed.
If it's not absolutely necessary to check between each program
statement, then /W is the preferred switch for event trapping.
NO [event] Trapping
QuickCompile Defaults to No Event Trapping as most programs don't
use ON [event] statements.
Source List File
This QuickCompile option is used to produce a Source list File
containing the address of each line in your source file. All
source text, it's size, and any error messages are also included.
Delete OBJ Code
This QuickCompile option cause the .OBJ file to be deleted after
Compiling and Linking are complete. This saves time and disk space.
Use this option on programs containing only one module (.BAS file).
However, if your program has more than one module, you may not want
to use this option. When changes are made to only one module of a
multi-module program, it is only necessary to recompile that module.
When compiling and linking multi-module programs, QuickCompile checks
to see which modules have changed by comparing the date/time stamp
of each modules source (.BAS) file and object (.OBJ) file.
Time and wear and tear on your disk will be saved because only
modules that have changed will be recompiled by BC. But, if you have
deleted a module's .OBJ file, it must be recompiled.
- 9 -
QuickCompile's Link Options
/E EXEPACK (optimized exe size)
Optimizes the load time allocation table by removing sequences of
repeated bytes (usually null characters). Linking with /E will
cause .EXE files to be smaller and load faster. This switch is
a QuickCompile and QB environment default. You will normally want
to always use this option.
NOTE: If you plan to use an executable file compressor (like
LZEXE or PKLITE), you should not use this switch. These
utilities will usually perform better on files that were
not previously packed with EXEPACK.
/PAU PAUSE before exe write
Causes LINK to pause and prompt you before writing the .EXE file.
Useful if you wish to insert another disk to write the .EXE file
to.
It's doubtful if hard disk users will ever want to use this option.
/I Show Link INFORMATION
Causes LINK to display information about the current linking
process. Shows the current phase in linking, and the name of
files being linked.
Although not normally necessary, this switch is helpful for
better understanding how link works.
/B BATCH mode (no prompts)
Causes LINK not to stop and prompt you when it cannot find a
file you specified. LINK continues to operate without prompting.
The only time this option is useful is when you are linking
several separate programs in one link session. Because QuickCompile
does not operate in this fashion, this switch is not helpful.
We advise you avoid this option because you will not be alerted
to errors.
- 10 -
/M Create MAPFILE
Creates a MAPFILE that list the program's segments and public
symbols sorted by address. See the QuickBASIC, Programming in
BASIC book for more details.
/LI MapFile with LINENUMBERS
Same as the /M option, but includes line number and addresses of
the source file.
/NOI NOIGNORECASE (observe case)
Normally, LINK does not distinguish between upper and lower case
letters. This option cause LINK to observe case.
/NOD NODEFAULTLIBRARY (using PDQ, etc...)
Normally, LINK will always include the BRUN or BCOM libraries
(which one depends on whether you specify QuickCompile's default
stand-alone or .EXE file requiring BRUNxx.EXE).
This option tells LINK not to include either. Use this option
when you are linking with a replacement library like PDQ.
QuickCompile automatically uses /NOD when you select PDQ.LIB as
a library to link with.
This option is also useful if you place the BRUN and BCOM libraries
in a path that LINK can't find. However, you must first select the
library within QuickCompile so LINK will know the new path.
We suggest that you place all libraries in the same path and set the
"LIB" environment variable so that QuickCompile will always know
where your libraries are. This will save time and unnecessary
keystrokes (or mouse clicks).
Place the line "SET LIB=<LibraryPath>" in your AUTOEXEC.BAT file,
where <LibraryPath> is the Drive/Directory where libraries are stored.
- 11 -
/NOE NOEXTDICTIONARY (using nocom, etc...)
Causes LINK to search the individual object files instead of the
dictionaries it has created to resolve certain conflicts.
NOTE: If you link with NOEM.OBJ or NOCOM.OBJ, (or PDQ's stub files)
you must use this option. In most cases, QuickCompile will
automatically select this option for you.
As suggested above about libraries, we also recommend that you set
an "OBJ" environment variable for the same reasons.
Place the line "SET OBJ=<ObjectPath>" in your AUTOEXEC.BAT file,
where <ObjectPath> is the Drive/Directory where object files are
stored. It's also best to place all special object files that
use often in this same directory.
/SE:<number> SEGMENTS
Sets the number of segments that LINK will allow your program to
have. You may specify any number from 1-1024. Default is 128. See
the QuickBASIC, Programming in BASIC book for more details.
/CO CODEVIEW preparation
Prepares an .EXE file for debugging with MicroSoft's CodeView
Debugger.
NOTE: The object files must have been previously compiled with the
/ZI option. See /ZI under QuickCompile's BC Options in this
booklet.
/FAR FAR
Used with the /PAC option below to help reduce the size and
increase the speed of your .EXE files.
WARNING: Although unlikely, circumstances may arise that will
cause this option to crash your program. If you use
this option, you should carefully test every function
of your program.
- 12 -
/PAC:<number> PACKCODE
Pack code segments. Causes link to group neighboring segment.
Code segments that are in the same group will have the same segment
address. You may specify the size limit of the groups. If not
specified, the size limit defaults to 65,530. See the QuickBASIC,
Programming in BASIC book for more details.
NOTE: This option may be used with the /FAR option to optimize
program execution speed and file size. See /FAR above for
more information and an important warning.
/ST:<number> STACK
This option allows you to specify how much memory to set aside
for use as the stack.
When a program has deeply nested calls to non-static procedures,
or a recursive subprogram is called many times, stack space may
become exhausted. /ST will allow you to set a larger stack size.
The QB default stack size is 2048 bytes. Maximum allowed stack
size is 65,535 bytes.
- 13 -
NOCOM.OBJ
(No Communications Routines)
When your source file includes an OPEN statement with a string variable in
it, BC will automatically include all com port routines. This happens
whether you are calling COM or not. 4K file in executable file size can be
saved by linking with NOCOM.OBJ in these cases. Linking with NOCOM.OBJ when
not necessary will increase your .EXE file size by 32 bytes, so observe the
the following rules.
OPEN FILE$ FOR INPUT AS #1 Will cause the com routines to be
included. You should link NOCOM.OBJ.
OPEN "MYFILE.TXT" FOR INPUT AS #1 Will not cause com routines to be
included. You should not link with
NOCOM.OBJ.
When Linking with NOCOM.OBJ you must specify the /NOE switch so that LINK
will search the object file instead of the dictionaries it has created
to resolve conflicts. QuickCompile automatically selects this option for
you.
Of course, if your program does use com routines, do not link with
NOCOM.OBJ.
When MicroSoft packaged QuickBASIC 4.5, they failed to include the object
file "NOCOM.OBJ". When you register QuickCompile, you receive (free of
charge) NOCOM.BAT and NOCOM.SRC. Run NOCOM.BAT from DOS to create a copy
of NOCOM.OBJ if you don't already have one.
NOEM.OBJ
(No Floating Point Emulation
Math Coprocessor installed.)
When a program will always be run on a computer with an 8087, 80287, or
80387 math coprocessor chip, QuickBASIC's software emulation of the math
chip's function are not necessary.
Linking such programs with NOEM.OBJ reduces the size of the executable
file by excluding emulation routines and speeds program execution by
allowing the coprocessor to operate.
When Linking with NOEM.OBJ you must specify the /NOE switch so that LINK
will search the object file instead of the dictionaries it has created
to resolve conflicts. QuickCompile automatically selects this option for
you.
If there is a possiblilty that a program will be run on a computer without
a math coprocessor, DO NOT link with NOEM.OBJ.
- 14 -
SMALLERR.OBJ
(No Error Messages)
If your program has been tested, and you feel that QuickBASIC's Error
Messages are not necessary at run time, you may further reduce the size
of the .EXE file by linking with SMALLERR.OBJ.
Linking with this file reduces program size about 1278 bytes by deleting
the text of error messages from your program. However, Error numbers will
still be displayed if a run time error does occur.
When Linking with SMALLERR.OBJ you must specify the /NOE switch so that
LINK will search the object file instead of the dictionaries it has
created to resolve conflicts. QuickCompile automatically selects this
option for you.
We suggest that you always link the final version of your program with
SMALLERR.OBJ. You'll still get error numbers that can be looked up in the
QuickBASIC manual if an error ever occurs.
EXISTS.BAS Module
(Check for existance of a file)
To help you avoid QuickBASIC's ON ERROR statements (and it effects on
program speed and file size), we have included a Basic Module for you
to add to your own programs.
EXISTS.BAS is used to determine if a file is present before your
program attempts to open it.
To add to this function to your program, load your program into the QB
Environment with the following line:
QB MYPROG.BAS /L QB
Then, select "Load File" from the "File" menu and add EXISTS.BAS as a
module. Add the following declaration to your program.
DECLARE FUNCTION Exists%(FileName$)
The following is an example of how Exists may be used in a program.
IF Exists%(FileName$) THEN
PRINT FileName$; "File found..."
ELSE
PRINT FileName$; "File not found..."
END IF
(cont.)
- 15 -
EXISTS.BAS uses QuickBASIC's Call InterruptX routine to check for the
existence of the specified file. For this reason, you will need to link
with QB.LIB (the default QB library included with QuickBASIC).
Be certain to select QB.LIB as a library to link with when using
QuickCompile.
We recommend that your programs should always check to see if a file is
present before trying to open it. This way, you can prevent user confusion
in case the file is not available.
The EXISTS.BAS file is heavily commented so that you can see exactly
how it works. Interrupts are a great way to perform tasks that
QuickBASIC can't.
CHK4QC
A small utility is included to check your QuickBasic source code for the
presence of QuickCompile headers. CHK4QC displays the version of
QuickCompile used and the date that the header was written.
Note: All source code files must have been saved in ASCII.
Using CHK4QC
You can run CHK4QC by simply typing the program name at the command prompt
or use one of the switches after the program name.
EXAMPLE:
CHK4QC /P Will send output to printer.
Valid Command Line Switches:
/P - Sends the output to your printer
/? - Displays online help screen
After running the program, a list of source code files in the current
directory will be displayed on your console. If the /P switch is used,
the output will be sent to the printer instead. To check files in any
directory, put CHK4QC in a directory listed in your path statement
and run CHK4QC from the desired directory.
- 16 -